/***************************************************************************************************
 *
 * Project: HZFlashcards
 *
 * Class: CharacterWordXRFCellRenderer
 *
 * File name: CharacterWordXRFCellRenderer.java
 *
 *
 * SVN:
 *
 *     $Rev$:
 *
 *     $Date$:
 *
 *     $LastChangedBy$:
 *
 *     $HeadURL$:
 *
 **************************************************************************************************/

package com.eastmountain.chinese.gui;

/*
 * ColorRenderer.java (compiles with releases 1.2, 1.3, and 1.4) is used by
 * TableDialogEditDemo.java.
 */

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;

@SuppressWarnings("serial")
public class CharacterWordXRFCellRenderer extends DefaultTableCellRenderer {

    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;

    public CharacterWordXRFCellRenderer( boolean isBordered ) {

        this.isBordered = isBordered;
        setOpaque( true ); // MUST do this for background to show up.
    }

    @Override
    public Component getTableCellRendererComponent( JTable table, Object obj, boolean isSelected,
                    boolean hasFocus, int row, int column ) {

        setValue( obj );

        return this;

    }

    @Override
    public void setValue( Object value ) {

        //System.out.println( " ****** setValue: " + value.getClass().getName() );

        setVerticalAlignment( SwingConstants.CENTER );
        setHorizontalAlignment( SwingConstants.CENTER );

        if ( "java.lang.String".equals( value.getClass().getName() ) ) {

            setText( (String) value );

        } else {

            setText( "Error" );

        }

    }

}
